package com.jxd.ordersys.service.impl;

import com.jxd.ordersys.dao.MealMapper;
import com.jxd.ordersys.model.Meal;
import com.jxd.ordersys.service.IMealService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName MealServiceImpl
 * @Description TODO
 * @Author 王云超
 * @Date 2024/9/19 16:46
 * @Version 1.0
 */
@Service
public class MealServiceImpl implements IMealService {

    //文件存放路径
    private static final String IMAGE_DIR = "src/main/resources/static/images/";

    @Autowired
    MealMapper mealMapper;

    @Override
    public List<Meal> getAllMeals() {
        return mealMapper.getAllMeals();
    }

    @Override
    public boolean addMeal(Meal meal) throws IOException {
        return mealMapper.addMeal(meal) > 0;
    }

    @Override
    public boolean editMeal(Meal meal) throws IOException {
        return mealMapper.editMeal(meal) > 0;
    }

    @Override
    public int delMealById(Integer mealId) {
        return mealMapper.delMealById(mealId);
    }

    @Override
    public boolean delMeals(List<Integer> mealIds) {
        int delCount =0;
        boolean delFlag = false;
        for (Integer mealId : mealIds) {
            delCount+=delMealById(mealId);
        }
        if (delCount>0){
            delFlag=true;
        }
        return delFlag;
    }

    @Override
    public Meal getMealById(Integer mealId) {
        return mealMapper.getMealById(mealId);
    }


}